var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const time = require('time-stamp')

var indexRouter = require('./routes/index'); 
let luoRouter = require('./routes/register');

var app = express();

//不同区域
const cors = require('cors');
app.use(cors());





app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());


// // 自定义中间件--携带时间
// app.use((req,res,next)=>{
//   req.time= time('YYYY年MM月DD日  HH:mm:ss');
//   next();
// })


app.use(express.static(path.join(__dirname, 'public')));
app.use('/static',express.static(path.join(__dirname,'static')))

app.use('/', indexRouter); 
app.use(luoRouter)

// catch 404 and forward to error handler
// app.use(function(req, res, next) {
//   res.send({code:404,msg:'not found'})
// });

// // error handler
// app.use(function(err, req, res, next) {
//   //  res.send({code:400,msg:err})
//   res.render('messge',{msg:err})
// });
app.use((err,req,res,next)=>{
    res.send({code:400,msg:err})
})


module.exports = app;
